import './index.less'
import { getAntd,getEcCom,getLabel } from '../../util/convert';
import * as mobx from 'mobx';
import * as _ from '../../util/public/common';

class main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            value: props.value ? props.value : ''
        };
    }

    componentWillReceiveProps(nextProps) {
        if (this.state.value !== nextProps.value) {
            this.setState({value: nextProps.value});
        }
    }

    render() {
        const { Row,Col,Card,Table } = getAntd();
        const { fieldObj, openDialogFunc, JSComplete, isPrint } = this.props;

        let specialobj  = fieldObj.specialobj ? mobx.toJS(fieldObj.specialobj) : [];
        let tableData = [];
        let expandedRowKeys = [];
        const tableColumn =  [
			{title:getLabel(502315, '流转顺序'), dataIndex:'num', key:'num', width:'8%'},
			{title:getLabel(33417,'节点'), dataIndex:'operator', key:'operator', width:'16%'},
            {
             title:
                <div className="column-location">
                    <span>{getLabel(500932, '位置信息')}</span>
                    { !isPrint == '1' && <span className="column-location-showmap" onClick={()=>{openDialogFunc(fieldObj)}}>{getLabel(384395, '查看地图')}</span>}
                </div>, 
            dataIndex:'time', key:'time', width:'20%', colSpan:4},
            {title:'', dataIndex:'location', key:'location', width:'56%', colSpan:0},
        ]


        specialobj.map(obj => {

            let rowDetail = [];

            obj.locationList.map(location => {
                rowDetail.push({
                    num: '',
                    key: `rowDetail_${obj.flowNum}`,
                    operator: location.userName + "/" + location.userDep,
                    time: location.time,
                    location: location.address,
                });
            })

            let nodeRowData = {
                num: obj.flowNum,
                key: `rowDataHead_${obj.flowNum}`,
                operator: obj.nodeName,
                nodeid : obj.nodeId,
                children:[{
                    num: '',
                    key: `rowDetailHead_${obj.flowNum}`,
                    operator: getLabel(17482,'操作人'),
                    time: getLabel(387601, '操作时间'),
                    location: getLabel(22981, '位置'),
                    children: rowDetail
                }]
            };
        
            expandedRowKeys.push(`rowDataHead_${obj.flowNum}`);
            expandedRowKeys.push(`rowDetailHead_${obj.flowNum}`);
    
            tableData.push(nodeRowData);
        })

        return (
            <div>
                {
                    specialobj.length > 0 && JSComplete ? 
                    <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@hpikxz`} span={24} style={{border:'1px solid #e9e9e9', position: "relative"}}>
                        <Table ecId={`${this && this.props && this.props.ecId || ''}_Table@l4p65v`} className="wf-location-field" pagination={false} columns={tableColumn} dataSource={tableData} expandedRowKeys={expandedRowKeys} size="middle"/>
                    </Col> : 
                    <span>{getLabel(126181, '暂无位置信息')}</span>
                }
            </div>
        )
    }
}

export default main
